<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="keyword" content="">

    <title>碰撞报告</title>

    <!-- Bootstrap core CSS -->
    <link href="__PUBLIC__/css/bootstrap.min.css" rel="stylesheet">
    <link href="__PUBLIC__/css/bootstrap-reset.css" rel="stylesheet">
    <!--external css-->
    <link href="__PUBLIC__/assets/font-awesome/css/font-awesome.css" rel="stylesheet" />
    <!-- Custom styles for this template -->
    <link href="__PUBLIC__/css/style.css" rel="stylesheet">
    <link href="__PUBLIC__/css/style-responsive.css" rel="stylesheet" />
    <!-- new styles-->
    <link href="__PUBLIC__/css/xxxstyle.css" rel="stylesheet" />

    <!--new dynamic table-->
    <link href="__PUBLIC__/assets/advanced-datatable/media/css/demo_page.css" rel="stylesheet" />
    <link href="__PUBLIC__/assets/advanced-datatable/media/css/demo_table.css" rel="stylesheet" />
    <link rel="stylesheet" href="__PUBLIC__/assets/data-tables/DT_bootstrap.css" />

      <!-- HTML5 shim and Respond.js IE8 support of HTML5 tooltipss and media queries -->
    <!--[if lt IE 9]>
      <script src="__PUBLIC__/js/html5shiv.js"></script>
      <script src="__PUBLIC__/js/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
  <section id="container" class="">
    <!--main content start-->
    <section id="main-content">
        <section class="wrapper site-min-height" id="collisionlist">
            <!-- page start-->
            <section class="panel">
                <header class="panel-heading"><i class="icon-file"></i>碰撞报告
                    <span class="pull-right">
                        <if condition="$pdata eq 1 && $_SESSION['pid'] neq ''"> 	 
                            <span class="btn btn-primary btn-xs"><a href="{:U('System/definition')}"><i class="glyphicon glyphicon-cog"></i>设置流程人员</a></span>                 
                        </if>
                        <if condition="$pdata eq 2 && $_SESSION['pid'] neq ''">
                            <button class="btn btn-success btn-xs" data-toggle="modal" href="#import_report_pz"><a href=""><i class="icon-share-alt"></i>导入报告</a></button>
                            <a class="btn btn-submit btn-xs" href="{:U('Bim/collision')}"><i class="icon-plus"></i>新建</a>                
                        </if>
                        <if condition="$pdata neq 2 && $pdata neq 1 && $_SESSION['pid'] neq ''">
                            <button class="btn btn-default btn-xs"><i class="glyphicon glyphicon-exclamation-sign"></i>暂无编制权限</button>
                        </if>
   					<if condition="$organ eq '' && $pdata eq 2 && $_SESSION['pid'] neq ''"> 	 
                        <a class="btn btn-submit btn-xs" href="{:U('Bim/explain',array('act'=>'add'))}"><i class="icon-pencil"></i>填写编制说明</a>
                    </if>
                    </span>
                </header>
                <div class="panel-body">
                    <div class="adv-table">
                   	   <div class="select-pos" style="margin-top:20px;">
                             <div name="Select-TaskType" class="task-option">
                                 <select class="styled" onchange="speed(this)">
                                     <option value="1" selected="selected">全部</option>
                                     <option value="2">待我审批</option>
                                 </select>
                             </div>
                              <div name="Select-TaskType" class="task-option">
                                 <select class="styled" onchange="theme(this)">
                                     <option value="0" selected="selected">主题筛选</option>
                                     <volist name="theme" id="list">
                                   		  <option value="{$list.id}">{$list.name}</option>
                                     </volist>
                                 </select>
                             </div>
                       </div>
                        <div id="ajaxcolist">
                      			
                        </div>
                    </div>
                </div>
            </section>
            <!-- <div class="row"><div class="col-xs-12 text-center">{$page}</div>		</div> -->

            <!-- page end-->
        </section>
        <!-- modal -->
    </section>
    <!--main content end-->
  </section>
  <!--导入碰撞报告（Modal） -->
         <div class="modal fade" id="import_report_pz" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title">导入碰撞报告</h4>
                                </div>
                                    <div class="modal-body">                                    
                                      <div class="uploadRow">
                                        <label class="btn btn-info btnUploadFile" for="pz-files-list">
                                          <input type="file" id="pz-files-list" onchange="JudgeFileType()"/>
                                          <i class="icon-folder-open"></i>
                                          选择报告
                                        </label>
                                      </div>
                                      <div id="ImportFeedback" class="pTypeA"></div>                                     
                                      <div id="progress" style="display: none;"></div>
                                      <pre id="zqOutput" style="display: none;"></pre>
                                      <pre id="output" style="display: none;"></pre>                                                                     
                                   </div>
                                <div class="modal-footer">
                                    <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                                    <button id="zqContent" class="btn btn-submit" type="button" style="display:none;">生成报告</button>
                                </div>
                            </div>
                        </div>
           </div>
  <!---->

    <!-- js placed at the end of the document so the pages load faster -->
    <script src="__PUBLIC__/js/jquery.js"></script>
    <script src="__PUBLIC__/js/jquery-1.8.3.min.js"></script>
    <script src="__PUBLIC__/js/bootstrap.min.js"></script>
    <script class="include" type="text/javascript" src="__PUBLIC__/js/jquery.dcjqaccordion.2.7.js"></script>
    <script src="__PUBLIC__/js/jquery.scrollTo.min.js"></script>
    <script src="__PUBLIC__/js/jquery.nicescroll.js" type="text/javascript"></script>
    <script src="__PUBLIC__/js/jquery.customSelect.min.js" ></script>
    <!--common script for all pages-->
    <script src="__PUBLIC__/js/common-scripts.js"></script>

    <!--dynamic table initialization -->
    <script type="text/javascript" language="javascript" src="__PUBLIC__/assets/advanced-datatable/media/js/jquery.dataTables.js"></script>
    <script type="text/javascript" src="__PUBLIC__/assets/data-tables/DT_bootstrap.js"></script>
    <script src="__PUBLIC__/js/dynamic_table_init.js"></script>
    <script src="__PUBLIC__/js/respond.min.js" ></script>

    <script type="text/javascript" src="__PUBLIC__/js/layer/layer.js"></script>

    <script type="text/javascript">
    $(document).ready(function(){
        ajaxcolist();
    });
    //判断文件类型
    function JudgeFileType(){
    	var file= $("#pz-files-list").val();
    	var filename=file.replace(/.*(\/|\\)/, "");  
    	var fileExt=(/[.]/.exec(filename)) ? /[^.]+$/.exec(filename.toLowerCase()) : ''; 
       // var k = val.substr(val.indexOf("."));
       if(fileExt != 'html'){
    	   $('#ImportFeedback').text('文件格式不能为'+fileExt+'，请导入HTML类型文件。');
    	   $('#zqContent').hide();
       }
       else {
          $('#ImportFeedback').text('导入文件成功！');
          $('#zqContent').show();
       }
    }

  //删除
    function del(id){
  	if(id){
  		layer.confirm('删除后不可恢复,确定删除吗?', {
       		  btn: ['确定','取消'] //按钮
       		}, function(){
  		 $.ajax({
  	          type : "POST",
  	          url:'__URL__/odel',
  	          data : {id:id},
  	          dataType : 'json',
  	          success: function(res){
  	        	  if(res.status==0){
  						layer.alert(res.info, {icon: 2});
  						return;
  					 }
  		 			 if(!res.errNo){
  		 				 layer.msg(res.msg,{icon:1});
  		 				 setTimeout("location.reload()",2000);
  			          }else{
  			        	 layer.msg(res.msg,{icon:2});
  			          }
  	          }
  	      });
     		}, function(){
      			// 取消
      		});
      			return false;
  	}
   }
    
    
        window.onload = function(){

            var EventUtil = {
                addHandler: function (element, type, handler) {
                    if (element.addEventListener) {
                        element.addEventListener(type, handler, false);
                    } else if (element.attachEvent) {
                        element.attachEvent("on" + type, handler);
                    } else {
                        element["on" + type] = handler;
                    }
                },
                removeHandler: function (element, type, handler) {
                    if (element.removeEventListener) {
                        element.removeEventListener(type, handler, false);
                    } else if (element.detachEvent) {
                        element.detachEvent("on" + type, handler);
                    } else {
                        element["on" + type] = null;
                    }
                },

                getEvent: function (event) {
                    return event ? event : window.event;
                },
                getTarget: function (event) {
                    return event.target || event.srcElement;
                },
                preventDefault: function (event) {
                    if (event.preventDefault) {
                        event.preventDefault();
                    } else {
                        event.returnValue = false;
                    }
                },
                stopPropagation: function (event) {
                    if (event.stopPropagation) {
                        event.stopPropagation();
                    } else {
                        event.cancelBubbles = true;
                    }
                },
                getRelatedTarget: function (event) {
                    if (event.relatedTarger) {
                        return event.relatedTarget;
                    } else if (event.toElement) {
                        return event.toElement;
                    } else if (event.fromElement) {
                        return event.fromElement;
                    } else { return null; }

                }

            }
            
            var filesList = document.getElementById("pz-files-list");       

            EventUtil.addHandler(filesList, "change", function(event){
                var info = "",
                    output = document.getElementById("output"),
                    ImportFeedback = document.getElementById("ImportFeedback"),
                    progress = document.getElementById("progress"),
                    files = EventUtil.getTarget(event).files,
                    type = "default",
                    reader = new FileReader();
                    reader.readAsText(files[0]);
                    type = "text";
                    
                reader.onerror = function(){
                    output.innerHTML = "Could not read file, error code is " + reader.error.code;
                };
                
                reader.onprogress = function(event){
                    if (event.lengthComputable){
                        progress.innerHTML = event.loaded + "/" + event.total;
                    }
                };
                
                reader.onload = function(){
                
                   var html = "";
                  // ImportFeedback.innerHTML = type;
                   // if(type == html ){
                   //    ImportFeedback.innerHTML = "上传文件格式正确";
                   // }
                   // else {
                   //    ImportFeedback.innerHTML = "上传文件格式错误";
                   // }
                    
                   switch(type){
                        case "image":
                            html = "<img src=\"" + reader.result + "\">";
                            break;
                        case "text":
                            html = reader.result;
                            break;
                            
                    } 
                    output.innerHTML = html;
                }; 
            }); 

            var zqContent = document.getElementById("zqContent");
            zqContent.onclick = function() {   
                var zqOutput = document.getElementById("zqOutput"),
                    tableInfo = "";    

                var tableObj = document.getElementsByClassName("mainTable")[0];    
				if(tableObj == undefined){
					layer.alert('文件生成失败,请确认导入文件是否正确', {icon: 2});
					return;
				}
                var data = new Array();
                for (var i = 2; i < tableObj.rows.length; i++) {  //遍历Table的所有Row
                    data[i] = new Array();
                	data[i][0] = tableObj.rows[i].cells[2].innerText;    
                	data[i][1] = tableObj.rows[i].cells[3].innerText;
                	data[i][2] = tableObj.rows[i].cells[4].innerText;    
                	data[i][3] = tableObj.rows[i].cells[6].innerText;    
                }
              if(data){
                	 $.ajax({
     	  		 		type : 'post',
     	  		 		url : '__URL__/imdata',
     	  		 		data : {data:JSON.stringify(data)},
     	  		 		dataType : 'json',
     	  		 		success : function(res){
     	  		 			 if(res.status==0){
     	 							layer.alert(res.info, {icon: 2});
     	 							return;
     	 						 }
     	  		 			 if(!res.errNo){
     	  		 				 layer.msg(res.msg,{icon:1});
     	  		 				 setTimeout("location.reload()",2000);
     	  			          }else{
     	  			        	 layer.msg(res.msg,{icon:2});
     	  			          }
     	  		 		}
     	  		     })
                }else{
                	 layer.msg('导入失败,出现未知错误,请重试',{icon:2});
                }
                //zqOutput.innerHTML = depData[6][12];
                // return tableInfo;
            }

        };   
        
        // 状况进度下拉
        function speed(o=1){
      	  var speed = o.value;
          ajaxcolist(speed);
        }
        // 状况进度下拉
        function theme(o=0){
      	  var themeid = o.value;
          ajaxcolist(1,themeid);
        }
        
        //ajaxcollist
        function ajaxcolist(speed=1,themeid=0){
        	if(speed==1){
        		var url = '__URL__/ajaxcolist';
        	}else{
        		var url = '__URL__/ajaxcolistt';
        	}
            $.ajax({
                type : "POST",
                url:url,
                data : {speed:speed,themeid:themeid},
                success: function(data){
                    $("#ajaxcolist").html('');
                    $("#ajaxcolist").append(data);
                }
            });
        }
    </script>

  </body>
</html>
